{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n",
      "/home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf#这里的tensorflow的版本是1.13.1\n",
    "from tensorflow.examples.tutorials.mnist import input_data#导入minist数据集所在的包\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import time\n",
    "import random\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1数据读取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From <ipython-input-2-6795a4af02e5>:2: read_data_sets (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use alternatives such as official/mnist/dataset.py from tensorflow/models.\n",
      "WARNING:tensorflow:From /home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:260: maybe_download (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please write your own downloading logic.\n",
      "WARNING:tensorflow:From /home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:262: extract_images (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use tf.data to implement this functionality.\n",
      "Extracting ./mnist_data/train-images-idx3-ubyte.gz\n",
      "WARNING:tensorflow:From /home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:267: extract_labels (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use tf.data to implement this functionality.\n",
      "Extracting ./mnist_data/train-labels-idx1-ubyte.gz\n",
      "WARNING:tensorflow:From /home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:110: dense_to_one_hot (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use tf.one_hot on tensors.\n",
      "Extracting ./mnist_data/t10k-images-idx3-ubyte.gz\n",
      "Extracting ./mnist_data/t10k-labels-idx1-ubyte.gz\n",
      "WARNING:tensorflow:From /home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:290: DataSet.__init__ (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Please use alternatives such as official/mnist/dataset.py from tensorflow/models.\n"
     ]
    }
   ],
   "source": [
    "#1准备数据，one_hot=true表示目标值用one-hot编码的形式去表达\n",
    "minist=input_data.read_data_sets(\"./mnist_data\",one_hot=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2数据探索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Datasets(train=<tensorflow.contrib.learn.python.learn.datasets.mnist.DataSet object at 0x7fc08e699f50>, validation=<tensorflow.contrib.learn.python.learn.datasets.mnist.DataSet object at 0x7fc08e76cb50>, test=<tensorflow.contrib.learn.python.learn.datasets.mnist.DataSet object at 0x7fc0d40c5350>) <class 'tensorflow.contrib.learn.python.learn.datasets.base.Datasets'>\n"
     ]
    }
   ],
   "source": [
    "print(minist,type(minist))#看一下mnist及其数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练集： <tensorflow.contrib.learn.python.learn.datasets.mnist.DataSet object at 0x7fc08e699f50>\n",
      "训练集的数据类型: <class 'tensorflow.contrib.learn.python.learn.datasets.mnist.DataSet'>\n"
     ]
    }
   ],
   "source": [
    "#训练集\n",
    "print(\"训练集：\",minist.train)\n",
    "print(\"训练集的数据类型:\",type(minist.train))#这里看一下mnist之中train的数据类型 我们这里需要的是mnist之中train中的images和labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练集minist.train中的images：\n",
      " [[0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " ...\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]]\n",
      "训练集minist.train中的images数据类型: <class 'numpy.ndarray'>\n",
      "训练集minist.train中的images的数据维度： (55000, 784)\n"
     ]
    }
   ],
   "source": [
    "print(\"训练集minist.train中的images：\\n\",minist.train.images)\n",
    "print(\"训练集minist.train中的images数据类型:\",type(minist.train.images))#既然是ndarray类型 那就看看数据的维度吧\n",
    "print(\"训练集minist.train中的images的数据维度：\",minist.train.images.shape)\n",
    "#minist.train.images是(55000, 784)的二维数组  ；minist.train.labels是(55000, 10)的二维数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练集minist.train中的labels：\n",
      " [[0. 0. 0. ... 1. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " ...\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 1. 0.]]\n",
      "训练集minist.train中的labels数据类型: <class 'numpy.ndarray'>\n",
      "训练集minist.train中的labels的数据维度： (55000, 10)\n"
     ]
    }
   ],
   "source": [
    "print(\"训练集minist.train中的labels：\\n\",minist.train.labels)\n",
    "print(\"训练集minist.train中的labels数据类型:\",type(minist.train.labels))#既然是ndarray类型 那就看看数据的维度吧\n",
    "print(\"训练集minist.train中的labels的数据维度：\",minist.train.labels.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在images中的元素索引: 1 \n",
      "labels本身的值： [0. 0. 0. 1. 0. 0. 0. 0. 0. 0.] \n",
      "对应代表的数字: 3\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAAO+ElEQVR4nO3df5BV9XnH8c/juiwRAgKmFJHEX9AGZYJ1g22kiQ1NomQMpqlG2nHoDM2ajHbMTKajtZ0RJzMNsYk20xqTNVBJxhozSRypMVGKTJlEiywG+eHagAwU1oXVMAmQWGTZp3/sMbPRPd+z3HN/7T7v18zOvfc89+x55sJnz733e7/3a+4uAGPfaY1uAEB9EHYgCMIOBEHYgSAIOxDE6fU82Dhr8/GaUM9DAqH8n36l1/24DVcrFXYzu1LSVyS1SPqGu69M3X+8JugyW1TmkAASNvn63FrFT+PNrEXSvZKukjRX0lIzm1vp7wNQW2Vesy+QtNvd97j765K+LWlJddoCUG1lwj5T0v4htw9k236LmXWYWZeZdZ3Q8RKHA1BGzd+Nd/dOd2939/ZWtdX6cABylAl7j6RZQ26fk20D0ITKhH2zpNlmdp6ZjZN0vaS11WkLQLVVPPTm7v1mdrOkJzQ49Lba3XdWrTMAVVVqnN3dH5f0eJV6AVBDfFwWCIKwA0EQdiAIwg4EQdiBIAg7EARhB4Ig7EAQhB0IgrADQRB2IAjCDgRB2IEgCDsQBGEHgiDsQBCEHQiCsANBEHYgCMIOBEHYgSAIOxAEYQeCIOxAEIQdCIKwA0EQdiAIwg4EQdiBIEqt4orRr2XunGT9xc9MSdZ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5y+jpf0vPZz85G9ybpIQ0+rTuhwfc2lkuaJmm9pF2S/lPS1Cbq7VuStkvapsFgzWhQbws1+BR9m6St2c/iRj92ib7q8rjxcVkgCN6gA4Ig7EAQhB0IgrADQRB2IAjCDgRB2IEg/h+E0IVyeLad3wAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "def show_image(i):\n",
    "    \"\"\"写一个函数，这里可以把mnist中的train中的一个images和它对应的lable显示出来\"\"\"\n",
    "    temp=minist.train.images[i]#获取mnist中images的第i个数据 此时是一个1x784的数组\n",
    "    temp=temp.reshape(28,28)#然后把它转成28x28的二维数据，目的是放入plt.imshow()中可视化出来\n",
    "    plt.imshow(temp)\n",
    "    print(\"在images中的元素索引:\",i,\"\\nlabels本身的值：\",minist.train.labels[i],\"\\n对应代表的数字:\",np.argmax(minist.train.labels[i]))\n",
    "show_image(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在images中的元素索引: 51729 \n",
      "labels本身的值： [0. 0. 0. 0. 0. 0. 0. 1. 0. 0.] \n",
      "对应代表的数字: 7\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAAMIElEQVR4nO3dX6wU5R3G8eepRQyoCdSWoBK0wIWkSbE5ARoJsSFV5Aa9EbmoNDE9mmiijYk19kIujakaL4z2WInQWP8kSuTCVCkxOdpE4tFQRWgrKkQQQcMFWlNE/fXijPaIZ/+4M7Oz8vt+ks3uzjs788uEh3d23p3zOiIE4OT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3X9uu2d9gea7iWDbYP2945YdlM21ttv1k8TzrHXkO1rbd9oDh2O2yvaqi2Obaft73L9hu2byyWN3rs2tTVl+PW9+/stk+R9G9Jv5S0X9LLktZGxK6+FtKC7b2ShiKi8R9g2F4u6WNJmyLiJ8WyOyUdiYg7iv8oZ0TE7waktvWSPm56Gu9itqLZE6cZl3S5pF+rwWPXpq4r1Yfj1kTPvljSnoh4OyI+lfSYpNUN1DHwImJU0pETFq+WtLF4vVHj/1j6rkVtAyEiDkbEq8XrjyR9Oc14o8euTV190UTYz5H07oT3+zVY872HpOdsv2J7uOliJjFrwjRb70ua1WQxk+g4jXc/nTDN+MAcu16mPy+LC3TftCwifibpMknXF6erAynGv4MN0thpV9N498sk04x/pclj1+v052U1EfYDkuZMeH9usWwgRMSB4vmwpM0avKmoD305g27xfLjher4ySNN4TzbNuAbg2DU5/XkTYX9Z0gLb59s+VdJVkrY0UMc32J5eXDiR7emSLtHgTUW9RdK64vU6SU83WMvXDMo03q2mGVfDx67x6c8jou8PSas0fkX+LUm/b6KGFnX9WNI/iscbTdcm6VGNn9Yd1/i1jWsk/UDSNklvSvqbpJkDVNufNT6192saD9bshmpbpvFT9Nck7Sgeq5o+dm3q6stx4+eyQBJcoAOSIOxAEoQdSIKwA0kQdiAJwg4kQdiBJP4Hkl6r5MyZAx0AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#从image的0-55000中随机的抽取个数据 然后显示一下\n",
    "show_image(random.randint(0,minist.train.images.shape[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在images中的元素索引: 41198 \n",
      "labels本身的值： [0. 0. 0. 0. 0. 0. 1. 0. 0. 0.] \n",
      "对应代表的数字: 6\n"
     ]
    },
    {
     "data": {
      "image/png": "i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R8x9g2P51SW9IeiAiPlRNu03S7oi4tfqHclpE3NAnvd0i6Y1eD+NdjVY0c/Qw45IuknSFevjdFfq6VF343nqxZl8oaXNEvBwRb0t6SNKSHvTR9yLiSUm73zV5iaQV1esVGvmfpetqeusLEbEjIp6tXu+V9M4w4z397gp9dUUvwn6ypFdG/b1N/TXee0j6lu1nbA/1upkxzIiIHdXrnZJm9LKZMTQcxrub3jXMeN98d80Mf94qDtC916KIWCDpk5KurjZX+1KM7IP107nTcQ3j3S1jDDP+U7387pod/rxVvQj7dkmzRv19SjWtL0TE9up5l6TH1H9DUb/6zgi61fOuHvfzU/00jPdYw4yrD767Xg5/3ouwr5E01/Yc2xMlfVrSEz3o4z1sT60OnMj2VEmfUP8NRf2EpMur15dLeryHvfyMfhnGu26YcfX4u+v58OcR0fWHpAs0ckT+fyT9eS96qOnrFyU9Vz2e73Vvkh7UyGbdfo0c27hS0s9JWi1pk6T/kDS9j3r7mqT1ktZpJFgze9TbIo1soq+TtLZ6XNDr767QV1e+N34uCyTBATogCcIOJEHYgSQIO5AEYQeSIOxAEoQdSOL/AUQKLddf9FzfAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#从image的0-55000中随机的抽取个数据 然后显示一下\n",
    "show_image(random.randint(0,minist.train.images.shape[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在images中的元素索引: 22587 \n",
      "labels本身的值： [0. 0. 1. 0. 0. 0. 0. 0. 0. 0.] \n",
      "对应代表的数字: 2\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly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jCDgRB2IEgCDsQBGEHgiDsQBDm7vXbmNkbkrb2WjRc0u/q1sCRadTeGrUvid7KVc3exrr7iL4KdQ37hzZu1uHurYU1kNCovTVqXxK9latevfE2HgiCsANBFB32hQVvP6VRe2vUviR6K1ddeiv0nB1A/RR9ZAdQJ4QdCKKQsJvZdDN7zcw2mdmcInrIY2ZbzGxtNg11R8G9LDKzTjNb12vZMDN71sw2Zo99zrFXUG8NMY13YprxQvdd0dOf1/2c3cyaJP1G0jRJ2yStknS1u79a10ZymNkWSa3uXvgHMMzsAklvSfqBu5+VLfumpD3ufm/2H+VQd7+9QXq7W9JbRU/jnc1W1NJ7mnFJl0r6GxW47xJ9Xak67LcijuxTJG1y983ufkDSI5JmFtBHw3P3FZL2fGDxTEmLs+eL1fOPpe5yemsI7r7D3Vdnz/dLenea8UL3XaKvuigi7KMkvd7r921qrPneXdIzZvaymbUV3UwfRrr7juz5Tkkji2ymDyWn8a6nD0wz3jD7rpzpzyvFBboPO9/d/1jSJZJuyN6uNiTvOQdrpLHTfk3jXS99TDP+niL3XbnTn1eqiLBvlzSm1++js2UNwd23Z4+dkh5X401FvevdGXSzx86C+3lPI03j3dc042qAfVfk9OdFhH2VpAlmdrqZHSfpKknLC+jjQ8zsxOzCiczsREkXq/Gmol4uaVb2fJakZQX28j6NMo133jTjKnjfFT79ubvX/UfSDPVckf+tpDuL6CGnr/GSfpX9rC+6N0lL1fO27qB6rm1cK+mjktolbZT0c0nDGqi3H0paK+kV9QSrpaDezlfPW/RXJK3JfmYUve8SfdVlv/FxWSAILtABQRB2IAjCDgRB2IEgCDsQBGEHgiDsQBD/D0LObXDLopr6AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#从image的0-55000中随机的抽取个数据 然后显示一下\n",
    "show_image(random.randint(0,minist.train.images.shape[0]))#这里随机抽取了3个 图片和标签大致是对的上的"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3准备搭建网络模型\n",
    "## 第一层\n",
    "### 卷积层：32个filter 大小5*5 步长strides=1 padding=\"SAME\"\n",
    "### 激活：relu\n",
    "### 池化：大小32*32 步长strides=2\n",
    "## 第二层\n",
    "### 卷积层：64个filter 大小5*5 步长strides=1 padding=\"SAME\"\n",
    "### 激活：relu\n",
    "### 池化：大小32*32 步长strides=2\n",
    "## 第三层\n",
    "### 全连接层"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "#训练集特征，虽然知道是55000行，784列，先不写上  这里用tensorflow里面的placeholder先占位，在session开始run的时候再填充\n",
    "#同理训练集特征，虽然知道是55000行，784列\n",
    "x=tf.placeholder(dtype=tf.float32,shape=(None,784))\n",
    "y_true=tf.placeholder(dtype=tf.float32,shape=(None,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "#先构造一个生成随机数的函数\n",
    "def creat_weight(shape):\n",
    "    '''输入一个shape 然后就返回这个变量的shape'''\n",
    "    return tf.Variable(initial_value=tf.random_normal(shape=shape))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From /home/stu_15527388015/.local/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Colocations handled automatically by placer.\n"
     ]
    }
   ],
   "source": [
    "#第一个卷积大层：包含一个卷积层、一个激活层、一个池化层\n",
    "with tf.variable_scope(\"di1daceng\"):\n",
    "    #输入的x是[None,784]  要把形状进行修改，-1表形状修改  修改成宽高28 28 通道为1\n",
    "    input_x = tf.reshape(x, shape=[-1, 28, 28, 1])\n",
    "\n",
    "    #卷积层\n",
    "    #设计的卷积层：32个filter 大小5x5 步长strides=1 padding=\"SAME\"\n",
    "    #定义filter和偏置\n",
    "    #用上面写好的creat_weight函数生成[5,5,1,32]的维度随机数的矩阵 卷积核尺寸是5x5 通道是1  32个卷积核\n",
    "    conv1_weigts=creat_weight(shape=[5,5,1,32])\n",
    "    #用上面写好的creat_weight函数生成[32]的维度随机数的矩阵 上面有32个卷积核 这里32个偏置\n",
    "    conv1_bias=creat_weight(shape=[32])\n",
    "    #输入的向量、卷积核filter和偏置都准备好了 然后放到卷积函数里面，如下面的运算 strides=[1,stride,stride,1]表示步长\n",
    "    #padding=\"SAME\"表示越过边缘取样 取样的面积和输入图像的像素宽度一致\n",
    "    conv1_x=tf.nn.conv2d(input=input_x,filter=conv1_weigts,strides=[1,1,1,1],padding=\"SAME\")+conv1_bias\n",
    "    #根据卷积核输出大小的计算公式  可以得出 这一步输出的图像大小是[None,28,28,32]\n",
    "\n",
    "    #激活层\n",
    "    #把上面设计的卷积网络conv1_x放入到激活函数relu之中\n",
    "    relu_x=tf.nn.relu(conv1_x)\n",
    "    #此时并不改变图像的维度，仍然还是[None,28,28,32]\n",
    "\n",
    "    #池化层\n",
    "    #设计的池化层：大小2x2 步长strides是2\n",
    "    #value表示：4-D tensor形状[batch,height,width,channels] channels这里不是图片通道数 而是池化的filter数量；把上步的输出relu_x喂入即可\n",
    "    #池化层的大小ksize[1,size,size,1]是2x2 步长strides=2 max_pool表示最大池化\n",
    "    # padding=\"SAME\"表示越过边缘取样 取样的面积和输入图像的像素宽度一致\n",
    "    pool1_x=tf.nn.max_pool(value=relu_x,ksize=[1,2,2,1],strides=[1,2,2,1],padding=\"SAME\")\n",
    "    # 根据池化核输出大小的计算公式  可以得出 这一步输出的图像大小是[None,14,14,32] 通道数是32"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "#第二个卷积大层：包含一个卷积层、一个激活层、一个池化层\n",
    "with tf.variable_scope(\"di2daceng\"):\n",
    "    #这一步的输入 就是上一个大层的输出 [None,14,14,32]\n",
    "\n",
    "    #卷积层\n",
    "    #设计的卷积层：64个filter 大小5x5 步长strides=1 padding=\"SAME\"\n",
    "    #定义filter和偏置\n",
    "    #用上面写好的creat_weight函数生成[5,5,1,32]的维度随机数的矩阵 卷积核尺寸是5x5 通道数是32 64个卷积核\n",
    "    conv2_weigts = creat_weight(shape=[5, 5, 32, 64])\n",
    "    #用上面写好的creat_weight函数生成[64]的维度随机数的矩阵 上面有64个卷积核 这里64个偏置\n",
    "    conv2_bias=creat_weight(shape=[64])\n",
    "    # 输入的向量、卷积核filter和偏置都准备好了 然后放到卷积函数里面，如下面的运算 strides=[1,stride,stride,1]表示步长\n",
    "    # padding=\"SAME\"表示越过边缘取样 取样的面积和输入图像的像素宽度一致\n",
    "    #这里的输入就是上一步的输出，所以input=pool1_x\n",
    "    conv2_x=tf.nn.conv2d(input=pool1_x,filter=conv2_weigts,strides=[1,1,1,1],padding=\"SAME\")+conv2_bias\n",
    "    #根据卷积核输出大小计算公式  这里的输出形状变成了[None,14,14,64]\n",
    "\n",
    "    #激活层  把上一步卷积conv2_x放进relu\n",
    "    relu2_x=tf.nn.relu(conv2_x)\n",
    "    #此时并不改变图像的维度，仍然还是[None,14,14,64]\n",
    "\n",
    "    #池化层\n",
    "    #设计的池化层：大小2x2 步长strides是2\n",
    "    #value表示：4-D tensor形状[batch,height,width,channels] channels这里不是图片通道数 而是池化的filter数量；把上步的输出relu_x喂入即可\n",
    "    #池化层的大小ksize[1,size,size,1]是2x2 步长strides=2 max_pool表示最大池化\n",
    "    # padding=\"SAME\"表示越过边缘取样 取样的面积和输入图像的像素宽度一致\n",
    "    pool2_x=tf.nn.max_pool(value=relu2_x,ksize=[1,2,2,1],strides=[1,2,2,1],padding=\"SAME\")\n",
    "    #根据池化核大小输出的公式 可以得出输出的形状是[None,7,7,64]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "#第三个层：全连接层\n",
    "with tf.variable_scope(\"di3daceng\"):\n",
    "    #全连接 就是矩阵相乘 要改变一下形状 上一步是[None,7,7,64] 样本量不变 但是后面要变[None,7*7*64],变成二维数组即矩阵\n",
    "    x_fc=tf.reshape(pool2_x,shape=[-1,7*7*64])\n",
    "    weight_fc=creat_weight(shape=[7*7*64,10])#乘以一个权重 [7*7*64,10]\n",
    "    bias_fc=creat_weight(shape=[10])#加上一个偏置[10]\n",
    "    y_predict=tf.matmul(x_fc,weight_fc)+bias_fc#输出预测值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From <ipython-input-16-fdb11f5be749>:2: softmax_cross_entropy_with_logits (from tensorflow.python.ops.nn_ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "\n",
      "Future major versions of TensorFlow will allow gradients to flow\n",
      "into the labels input on backprop by default.\n",
      "\n",
      "See `tf.nn.softmax_cross_entropy_with_logits_v2`.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "#3构建损失函数\n",
    "error=tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_true,logits=y_predict))\n",
    "#4优化损失\n",
    "optimizer=tf.train.GradientDescentOptimizer(learning_rate=0.01).minimize(error)\n",
    "\n",
    "#准确率计算\n",
    "equal_list=tf.equal(tf.argmax(y_true,1),tf.argmax(y_predict,1))\n",
    "accuracy=tf.reduce_mean(tf.cast(equal_list,tf.float32))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4模型训练与输出准确率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练之前，损失为：2795.61572265625\n",
      "第0次训练的损失为2795.61572265625,准确率为:0.12330909073352814\n",
      "第1次训练的损失为5736.771484375,准确率为:0.19432727992534637\n",
      "第2次训练的损失为5177.21142578125,准确率为:0.15592727065086365\n",
      "第3次训练的损失为655.2330932617188,准确率为:0.08296363800764084\n",
      "第4次训练的损失为307.6154479980469,准确率为:0.12639999389648438\n",
      "第5次训练的损失为114.92292785644531,准确率为:0.1093272715806961\n",
      "第6次训练的损失为65.74300384521484,准确率为:0.11029090732336044\n",
      "第7次训练的损失为46.923580169677734,准确率为:0.10916363447904587\n",
      "第8次训练的损失为37.465885162353516,准确率为:0.11481817811727524\n",
      "第9次训练的损失为33.794063568115234,准确率为:0.10525454580783844\n",
      "第10次训练的损失为30.144672393798828,准确率为:0.10636363923549652\n",
      "第11次训练的损失为29.221017837524414,准确率为:0.12121818214654922\n",
      "第12次训练的损失为27.634599685668945,准确率为:0.11247272789478302\n",
      "第13次训练的损失为27.615169525146484,准确率为:0.10710909217596054\n",
      "第14次训练的损失为25.578781127929688,准确率为:0.09121818095445633\n",
      "第15次训练的损失为26.446441650390625,准确率为:0.1011272743344307\n",
      "第16次训练的损失为30.811481475830078,准确率为:0.10474545508623123\n",
      "第17次训练的损失为26.142276763916016,准确率为:0.10476363450288773\n",
      "第18次训练的损失为23.66813087463379,准确率为:0.10649091005325317\n",
      "第19次训练的损失为24.127216339111328,准确率为:0.10498181730508804\n",
      "第20次训练的损失为24.122541427612305,准确率为:0.11183636635541916\n",
      "第21次训练的损失为22.595781326293945,准确率为:0.105636365711689\n"
     ]
    }
   ],
   "source": [
    "#变量初始化\n",
    "init=tf.global_variables_initializer()\n",
    "#开启会话\n",
    "start=time.time()\n",
    "with tf.Session() as sess:\n",
    "    sess.run(init)\n",
    "    #上面x和y_true先用placehoder占位了 没有输入具体的值 这里把样本喂入\n",
    "    imge=minist.train.images[:]\n",
    "    lable=minist.train.labels[:]\n",
    "    print(\"训练之前，损失为：{}\".format(sess.run(error,feed_dict={x:imge,y_true:lable})))\n",
    "    #开始训练\n",
    "    for i in range(3001):\n",
    "        _,loss,accuracy_value=sess.run([optimizer,error,accuracy],feed_dict={x:imge,y_true:lable})\n",
    "        print(\"第{}次训练的损失为{},准确率为:{}\".format(i,loss,accuracy_value))   \n",
    "        if i==3000:\n",
    "            print(\"最终训练出来的准确率为:{}\".format(accuracy_value))\n",
    "\n",
    "end=time.time()\n",
    "print(\"网络训练运行时间是{}\".format(end-start))            #训练实在太慢 臣妾先停止了  机器不太给力 后续有机会再重新训练吧"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
